<template>
	<view>
		<view class="goods-item" @click="gotoDetail()">
		    <!-- 左半部 -->
		    <view class="left">
        <radio :checked="goods.goods_state" color="#C00000" v-if='showRadio' @click='radioChange'></radio>
		      <image :src="goods.goods_small_logo || defaultPic" mode="widthFix"></image>
		    </view>
		    <!-- 右半部 -->
		    <view class="right">
		      <view class="content">
		        {{goods.goods_name}}
		      </view>
          <view class="pn">
            <view class="price">
              ￥{{goods.goods_price | toFixed}}
            </view>
            <uni-number-box @change="numChange" :min="1" :value="goods.goods_count"></uni-number-box>
          </view>
		  </view>
		  
		</view>
	</view>
</template>

<script>
	export default {
    props:{
      goods:{
        type:Object,
        default:{}
      },
      showRadio:{
        type:Boolean,
        default:false
      }
    },
    filters:{
      // 过滤器把数字处理为带2位小数的数字
      toFixed(num){
        return Number(num).toFixed(2)
      }
    },
		data() {
			return {
			defaultPic:"http://image2.suning.cn/uimg/b2c/newcatentries/0000000000-000000000168415104_1_400x400.jpg",
			};
		},
    methods:{
      gotoDetail(){
        this.$emit('click')
      },
      
      radioChange(){
        this.$emit('radio')
      },
      
      numChange(e){
        this.$emit('num',{
          goods_id:this.goods.goods_id,
          goods_count: +e
        })
      }
    }
	}
</script>

<style lang="scss">
.goods-item{
    display: flex;
    border-bottom: 1px solid #efefef;
    .left{
      display: flex;
      padding: 0 10px;
      justify-content: space-between;
      align-items: center;
      width: 300rpx;
      margin-right: 20rpx;
      image{
        width: 300rpx;
      }
 
    }
    
    .right{
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding: 20rpx 0;
      .content{
        font-size: 12px;
        padding-top: 10rpx;
      }
      .pn{
        display: flex;
        justify-content: space-between;
        align-items: cneter;
        .price{
          color: #c00000;
          padding-top: 10px;
        }
      }
    }
    
  }
</style>

